Overview
This post describes how to use GitHub, Travis CI, and PlatformIO to automatically test build Arduino libraries.
Background
Modern languages and frameworks typically have mature, well-developed facilities for performing unit, integration, and functional testing. The Arduino/C++ platform is not as well-developed in terms of automated testing. Developers traditionally rely on manual testing of libraries (build via Arduino IDE) which is slow, prone to human error, and limit the ability to test against multiple hardware architectures.
|
|
Prerequisites
The following are required:
- GitHub account
- Travis CI account
- You can sign in with your GitHub account
- Arduino library
- PlatformIO
- Mac OS X:
brew install platformio(v3.0.1 used)
- Mac OS X:
Example
In the following example, the ModbusMaster Arduino library code is hosted on GitHub and Travis CI is configured to run for each push to the repository.
GNU make is used to build the example sketches included with the library for each of 5 commonly used Arduino boards. During development, the command may be run from the console in order to build against individual boards or the entire set. The Makefile in the root directory of the library defines the build process and is configured to parallelize the Travis CI builds for multiple hardware architectures.
Makefile settings: adjust, as required; they are identical for all my projects.
FIND- points to bashfindcommandDIR- location of examples to build; this directory will be recursively searched for source filesCRITERIA- search for*.ino(newer) or*.pde(older) filesBUILD- points to bashplatformiocommandLIB- location of library to include in build
Makefile targets: run from the console for all or specific board testing.
make all- runsmake uno,make due,make huzzah,make genuino101,make teensy31make uno- setsPLATFORMIO_BOARD=unofollowed bymake buildmake due- setsPLATFORMIO_BOARD=duefollowed bymake buildmake huzzah- setsPLATFORMIO_BOARD=huzzahfollowed bymake buildmake genuino101- setsPLATFORMIO_BOARD=genuino101followed bymake buildmake teensy31- setsPLATFORMIO_BOARD=teensy31followed bymake build
Makefile targets: call from Travis CI to conduct builds in parallel.
make build- iterates through example directory, building each one in series
|
|
The .travis.yml configures Travis CI. In this example, Travis CI will run 5 parallel builds–1 for each PLATFORMIO_BOARD setting.
|
|
Usage
While developing the library, run make from the console to build all examples against all boards configured in the Makefile.
|
|
When code is pushed to the GitHub repository, Travis CI will automatically build all examples against each hardware architecture. Failed builds will be flagged in Pull Requests / commits so they may be resolved prior to merge.
Summary
GitHub, Travis CI, and PlatformIO provide an effective platform for continuous integration test building of Arduino libraries. This integration assures the developer that their library compiles cleanly against selected hardware platforms.
((( - )))
Resources
kyab / travis-test-arduino - inspiration for my use of PlatformIO
4-20ma / ModbusMaster - example library illustrating Arduino continuous integration
PlatformIO / PlatformIO - open source ecosystem for IoT development
Arduino Reference / Libraries
Gnu / Introduction to Makefiles
Wikipedia / make
Wikipedia / Makefile